<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        table {
            border-collapse: collapse;
            text-align: center;
            width: 400px;
        }
    </style>
    <!-- <script src="../jquery-1.12.4.js"></script>
    <script>
        $(function(){
            //点击全选或者全不选,全部选择或者取消
            $('.checkall').on('click',function(){
                $('.box input').prop('checked',$(this).prop('checked'))
            })
            //点击小复选框,判断是否全部选上,来设置全选是否打钩
            $('.box .check').bind('click',function(){
                var ischecked = true;
                $('.box .check').each(function(index,element){
                    if(!$(element).prop('checked')) {
                        ischecked = false;
                    }
                })
                $('.checkall').prop('checked',ischecked)
            })
            //点击反选按钮,进行反选
            $('#btn').on('click',function(){
                var ischecked = true;
                $('.box .check').each(function(index,element){
                    if($(element).prop('checked')){
                        $(element).prop('checked',false);
                        ischecked = false;
                    } else {
                        $(element).prop('checked',true);
                    }
                })
                $('.checkall').prop('checked',ischecked)
            })
        })
    </script> -->
</head>
<body>
    <div class="box">
        <table border='1px'>
            <caption><button id='btn'>反选</button></caption>
            <thead>
                <tr>
                    <th><input type="checkbox" class='checkall'>全选/全不选</th>
                    <th>名称</th>
                    <th>厂家</th>
                    <th>价格</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>ipad</td>
                    <td>apple</td>
                    <td>6666</td>
                </tr>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>iphone</td>
                    <td>apple</td>
                    <td>7777</td>
                </tr>
                <tr>
                    <td><input type="checkbox" class='check'></td>
                    <td>ipro</td>
                    <td>apple</td>
                    <td>8888</td>
                </tr>
            </tbody>
        </table>
    </div>
    <!-- <script>
        //获取元素
        var checkall = document.getElementsByClassName('checkall')[0];
        var checkList = document.getElementsByClassName('check');
        var btn = document.getElementById('btn');

        // 注册事件
        // 1,点击全选或者全不选,子项全部跟随一样的选择
        checkall.onclick = function(){
            for(var i = 0; i < checkList.length; i++) {
                checkList[i].checked = this.checked;
            }
        }
        //2,点击子项,判断是否全选,则全选选中,否则不选中
        for(var i = 0; i < checkList.length; i++) {
            var check = checkList[i];
            check.onclick = function(){
                var ischecked = true;
                for(var i = 0; i < checkList.length; i++) {
                    if(!checkList[i].checked){
                        ischecked = false;
                    }
                }
                checkall.checked = ischecked;
            }
        }
        //3,反选
        btn.addEventListener('click',function(){
            var ischecked = true;
            for(var i = 0; i < checkList.length; i++) {
                if(checkList[i].checked){
                    checkList[i].checked = false;
                    ischecked = false;
                } else {
                    checkList[i].checked = true;
                }
            }
            checkall.checked = ischecked;
        })
    </script> -->
</body>
</html>